package org.ansel.tools.eza;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;

public class DemoLog {
	/** 用于生成文件列表结果。*/
	private static Logger loggerRvt = null;
	/** 正常的日志文件。*/
	private static Logger logger = null;
	public DemoLog(){
		LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
		String logbackConfigPath = this.getClass().getResource("/eza/logback4Rvt.xml").toString();//读取jar包内配置文件路径
		logbackConfigPath=logbackConfigPath.replace("file:", "");
        if (logbackConfigPath != null) {
        	try {
                JoranConfigurator configurator = new JoranConfigurator();
                configurator.setContext(loggerContext);
                loggerContext.reset();
                configurator.doConfigure(logbackConfigPath);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        loggerRvt=loggerContext.getLogger("rvtfile");
        logger=loggerContext.getLogger(this.getClass());
	}
	private static volatile DemoLog thisclass;
	public static DemoLog getInstance(){
		if(thisclass==null){
			synchronized (DemoLog.class) {
				if(thisclass==null){
					thisclass = new DemoLog();
				}
			}
		}
		return thisclass;
	}
	public void testLogback() {
		logger.info("Start testLogback");
		loggerRvt.info("something good");
		String outerfilepath=System.getProperty("user.dir");//读取jar包外部配置文件
		outerfilepath+="/zippathfile-dev.txt";
		outerfilepath=outerfilepath.replace("file:","");
		logger.debug("outerfilepath is "+outerfilepath);
		File outfile = new File(outerfilepath);
		logger.info("outerfile.size is "+outfile.getTotalSpace());;
		logger.info("end testLogback");
	}
	
	public static void main(String[] args) {
		DemoLog demo = DemoLog.getInstance();
		demo.testLogback();
	}
}
